package com.example.shixunandjavagotoyangchen.BoosYang.Day001;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00105.ClassroomDay00105Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00105.ClassroomDay00105Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00106.HappyDay00106Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00106.HappyDay00106Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00106.HappyDay00106Contion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00106.HappyDay00106Model;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00106.HappyDay00106Presenter;
import com.example.shixunandjavagotoyangchen.R;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;


public class BlankFragmentDay00106 extends BasterFragment implements HappyDay00106Contion.vier, OnRefreshLoadMoreListener {


    public HappyDay00106Presenter presenter;
    public static SmartRefreshLayout HappySmartRefreshLayout;
    private RecyclerView HappyRecyclerView;
    public boolean ishappy = true;
    public int happybuju = 0;
    public int happynum =50;
    public HappyDay00106Adpter adpter;


    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day00106;
    }

    @Override
    public void initView() {

        HappySmartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.Happy_SmartRefreshLayout);
        HappyRecyclerView = (RecyclerView) findViewById(R.id.Happy_RecyclerView);
        HappySmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        HappyRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));


        presenter = new HappyDay00106Presenter(this,new HappyDay00106Model());
        presenter.happying("/video/findVideos?currentPage="+happynum+"&pageSize=10");




    }

    @Override
    public void initDate() {

    }

    @Override
    public void getvier(List<HappyDay00106Bean.DataBean> dataBeans) {

        for (HappyDay00106Bean.DataBean dataBean : dataBeans) {
            dataBean.setHappyLayout(++happybuju);
            if (happybuju==4){
                happybuju=0;
            }
        }
        HappySmartRefreshLayout.finishLoadMore();
        HappySmartRefreshLayout.finishRefresh();
        if (adpter==null){
            adpter = new HappyDay00106Adpter(dataBeans);
            HappyRecyclerView.setAdapter(adpter);
        }else {
            if (ishappy){
                adpter.getData().clear();
            }
            adpter.getData().addAll(dataBeans);
            adpter.notifyDataSetChanged();
        }
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        ishappy=false;
        happynum++;
        presenter.happying("/video/findVideos?currentPage="+happynum+"&pageSize=10");
        Log.i("BlankFragmentDay001","---06加载:"+happynum);
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

        if (ishappy){
            happynum=50;
        }
        presenter.happying("/video/findVideos?currentPage="+happynum+"&pageSize=10");
        Log.i("BlankFragmentDay001","---06刷新:"+happynum);
    }
}
